﻿using System;
using System.Windows;
using System.Windows.Media.Animation;
using Core;

namespace TallyJ.Announcer
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  internal partial class AnnouncerWindow : IAnnouncerView
  {
    private AnnouncerPresenter _announcerPresenter;

    ///<summary></summary>
    public AnnouncerWindow()
    {
      InitializeComponent();
      WindowState = WindowState.Maximized;
    }

    #region IAnnouncerView Members

    public AnnouncerDataContext LocalDataContext
    {
      set { DataContext = value; }
    }

    ///<summary></summary>
    public AnnouncerPresenter Presenter
    {
      set
      {
        _announcerPresenter = value;
        _announcerPresenter.DoAnimation += OnAnimate;
        KeyDown += _announcerPresenter.OnKeyDown;
        MouseWheel += _announcerPresenter.OnMouseWheel;
      }
    }


    ///<summary>Expose the dispatcher to presenters</summary>
    ///<param name="action"></param>
    public void ViewDispatcherAction(Action action)
    {
      this.DispatcherAction(action);
    }
     
    #endregion

    ///<summary>Does animation</summary>
    ///<param name="sender"></param>
    ///<param name="args"></param>
    public void OnAnimate(object sender, AnimateTypeArg args)
    {
      try
      {
        var storyboard = (Storyboard) Resources[args.AnimationName];
        storyboard.Begin(border, HandoffBehavior.Compose);
      }
      catch (Exception e)
      {
        MessageBox.Show(e.AllMessages());
      }
    }

    /* 
    private void SetupCornerDisplay()
    {
      // show now
      ClockTimerOnElapsed(null, null);

      _clockTimer = new Timer
                      {
                            Interval = 1000
                      };
      _clockTimer.Elapsed += ClockTimerOnElapsed;
      _clockTimer.Start();
      // not working??
    }

    private void ClockTimerOnElapsed(object sender, ElapsedEventArgs args)
    {
      tbClockDisplay.DispatcherAction(delegate { tbClockDisplay.Text = DateTime.Now.ToString("h:mm:ss tt"); });
    }
*/
  }
}